package com.open.rbac.model.vo.sys;

import java.time.LocalDate;
import java.util.List;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;

import com.open.rbac.constant.GenderType;
import com.open.rbac.model.vo.sys.group.UpdatePassword;
import com.open.rbac.model.vo.sys.group.UserCreate;
import com.open.rbac.model.vo.sys.group.UserUpdate;

/**
 * 用户参数
 *
 * @author Riche's
 * @since 2022/8/18
 */
@Schema(name = "UserVo", description = "用户参数")
@Getter
@Setter
public class UserVo {

    @Schema(description = "用户ID")
    @NotBlank(message = "用户ID为必填项", groups = {UserUpdate.class, UpdatePassword.class})
    private String id;

    @Schema(description = "用户名")
    @NotBlank(message = "用户名为必填项", groups = UserCreate.class)
    @Size(min = 4, max = 34, message = "用户名长度在 4~32 之间")
    @Pattern(regexp = "^[a-z0-9_-]{4,32}$",
            message = "用户名长度在 4~32 之间，且只能为小写、数字、下划线的组合", groups = UserCreate.class)
    private String username;

    @Schema(description = "密码")
    @NotBlank(message = "密码为必填项", groups = {UpdatePassword.class})
    @Size(min = 5, max = 30, message = "密码长度在5~30之间", groups = {UpdatePassword.class})
    private String password;

    @Schema(description = "真实姓名或昵称")
    @NotBlank(message = "姓名为必填项", groups = {UserCreate.class, UserUpdate.class})
    @Size(min = 1, max = 32, message = "姓名长度在 1~32 之间",
            groups = {UserCreate.class, UserUpdate.class})
    private String realname;

    @Schema(description = "生日")
    @NotNull(message = "生日为必选项", groups = {UserCreate.class, UserUpdate.class})
    private LocalDate birthday;

    @Schema(description = "性别，取值：Male/Female")
    @NotNull(message = "性别为必选项，且取值只能为 Male/Female", groups = {UserCreate.class, UserUpdate.class})
    private GenderType gender;

    @Schema(description = "电子邮箱")
    //@NotBlank(message = "邮箱为必填项", groups = {UserCreate.class, UserUpdate.class})
    //@Email(message = "邮箱格式不符合规则", groups = {UserCreate.class, UserUpdate.class})
    private String email;

    @Schema(description = "手机号码")
    @NotBlank(message = "手机号码为必填项", groups = {UserCreate.class, UserUpdate.class})
    @Pattern(regexp = "^[1][3,5,7,8][0-9]\\d{8}$", message = "手机号码不符合规则",
            groups = {UserCreate.class, UserUpdate.class})
    private String phone;

    private String avatar;

    @Schema(description = "是否已启用")
    private boolean enable;

    @Schema(description = "备注")
    @Size(max = 255, message = "备注最长不能超过255个字符")
    private String remark;

    @Schema(description = "用户所属角色列表")
    @NotEmpty(message = "用户所属角色为必选项", groups = {UserCreate.class, UserUpdate.class})
    private List<String> roleIds;

    @Schema(description = "用户所属的组织机构列表")
    @NotEmpty(message = "用户所属组织机构为必选项", groups = {UserCreate.class, UserUpdate.class})
    private List<String> organizationIds;

}
